package com.ablog.service.impl;

import com.ablog.model.System;
import com.ablog.dao.SystemMapper;
import com.ablog.service.SystemService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * (System)表服务实现类
 *
 * @author mopeiwen
 * @since 2020-07-22 13:11:20
 */
@Service
@Transactional
public class SystemServiceImpl implements SystemService {
    @Resource
    private SystemMapper systemMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public System queryById(String id) {
    	System system = this.systemMapper.selectByPrimaryKey(id);
    	
    	//系统访问量+1
    	system.setVisits(system.getVisits()+1);
    	this.systemMapper.updateByPrimaryKeySelective(system);
    	
        return system;
    }
    
    /**
     * 通过System对象查询集合
     *
     * @param system 实例对象
     * @return 实例对象
     */
    @Override
    public List<System> queryAll(System system) {
        return this.systemMapper.selectAll(system);
    }

    /**
     * 新增数据
     *
     * @param system 实例对象
     * @return 实例对象
     */
    @Override
    public System add(System system) {
        this.systemMapper.insertSelective(system);
        return system;
    }

    /**
     * 修改数据
     *
     * @param system 实例对象
     * @return 实例对象
     */
    @Override
    public System update(System system) {
        this.systemMapper.updateByPrimaryKeySelective(system);
        return this.queryById(system.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean delById(String id) {
        return this.systemMapper.deleteByPrimaryKey(id) > 0;
    }
}